package com.qianfeng.bob.xiexiaobo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.toolbox.NetworkImageView;
import com.qianfeng.bob.xiexiaobo.R;
import com.qianfeng.bob.xiexiaobo.bean.HomeFragmentDatas;

import java.util.List;

/**
 * Created by Bob on 2015/12/17.
 */
public class HomeFragementAdapter  extends MyBaseAdapter{
    private List<HomeFragmentDatas.DataEntity.ItemsEntity> mDatas;
    public HomeFragementAdapter(Context context, List<HomeFragmentDatas.DataEntity.ItemsEntity> datas) {
        super(context, datas);
        this.mDatas = datas;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent, LayoutInflater inflater, List datas) {

        ViewHolder holder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.shopping_search_item, parent, false);
            holder = new ViewHolder(convertView);
            holder.description = (TextView) convertView.findViewById(R.id.tv_shopping_search_description);
            holder.price = (TextView) convertView.findViewById(R.id.tv_shopping_search_price);
            holder.country = (TextView) convertView.findViewById(R.id.tv_shopping_search_country);
            holder.nationalFlag = (ImageView) convertView.findViewById(R.id.niv_shopping_search_nationflag);
            holder.pic = (ImageView) convertView.findViewById(R.id.niv_shopping_search_pic);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        HomeFragmentDatas.DataEntity.ItemsEntity item =  mDatas.get(position);
        holder.description.setText(item.getComponent().getDescription());
        holder.price.setText("￥" + item.getComponent().getPrice());
        holder.country.setText(item.getComponent().getCountry());


        holder.nationalFlag.setTag(item.getComponent().getNationalFlag());
        holder.pic.setTag(item.getComponent().getPicUrl());

        loadImage(holder.nationalFlag);
        loadImage(holder.pic);

        return convertView;
    }
    public   class ViewHolder{
        public ViewHolder(View convertView){
            description = (TextView) convertView.findViewById(R.id.tv_shopping_search_description);
            price = (TextView) convertView.findViewById(R.id.tv_shopping_search_price);
            country = (TextView) convertView.findViewById(R.id.tv_shopping_search_country);
            nationalFlag = (ImageView) convertView.findViewById(R.id.niv_shopping_search_nationflag);
            pic = (ImageView) convertView.findViewById(R.id.niv_shopping_search_pic);
        }
        TextView description;
        TextView price;
        TextView country;
        ImageView pic;
        ImageView nationalFlag;

    }

}
